package com.example.jmeterTest.controller;

import com.example.jmeterTest.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Mono;

import java.util.concurrent.Semaphore;


@RestController
@RequestMapping("/semaphore")
public class SemphoreController {


    @Autowired
    private Semaphore semaphore;

    @PostMapping("/test")
    public User addUser() {

        try {
            semaphore.acquire();
            Thread.sleep(500);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }finally {
            semaphore.release();
        }

        return new User();
    }
}
